function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i].trim();
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
    }
    return "";
}
layui.define(["table", "form", "admin", "upload"], function (exports) {
    var $ = layui.$,
        table = layui.table,
        form = layui.form,
        upload = layui.upload,
        admin = layui.admin;
    var adminid = Number(getCookie("uid"));

    table.render({
        elem: '#LAY-livehistory-manage'
        , url: '/admin/live/get_history'
        , cols: [[
            { field: 'id', title: 'ID', fixed: "left", width: 70 }
            , { field: 'anchorid', title: '主播ID', fixed: "left", width: 100 }
            , {
                field: '', title: '主播昵称', fixed: "left", width: 120, templet: function (d) {
                    return d.anchor ? d.anchor.nick_name : '';
                }
            },
            {
                field: "",
                title: "平均时长",
                width: 100,
                templet: function (d) {
                    return (
                        "<a style='color:red' lay-event='user_duration'>" + d.avg_duration + "</a>"
                    );
                },
            },
            , { field: 'start_stamp_str', title: '开播时间', width: 162 }
            , { field: 'end_stamp_str', title: '结束时间', width: 162 }
            , { field: 'live_minute', title: '直播时长', width: 130 }
            , { field: 'title', title: '直播标题', width: 150 }
            , {
                field: '', title: '直播分类', width: 100, templet: function (d) {
                    return d.category ? d.category.title : '';
                }
            },
            {
                field: "open_chat_num",
                title: "<font color=green>点击私信人数</font>",
                width: 130,
                sort: true,
            },
            {
                field: "send_chat_num",
                title: "<font color=green>发起私信人数</font>",
                width: 130,
                sort: true,
            },
            , {
                field: '', title: '联赛名称', width: 170, templet: function (d) {
                    return d.matches ? d.matches.comp : '';
                }
            }
            , {
                field: '', title: '主队名称', width: 120, templet: function (d) {
                    return d.matches ? d.matches.home : '';
                }
            }
            , {
                field: '', title: '客队名称', width: 120, templet: function (d) {
                    return d.matches ? d.matches.away : '';
                }
            },

            { field: 'gift_profit', title: '收益宝石', width: 100 }
            , { field: 'other_gift_price', title: '收益钻石', width: 100 }
            , { field: 'high_count', title: '观看峰值', width: 100, sort: true, }
            , { field: 'viewer_count', title: '观众(登录用户)', width: 130, sort: true, }
            // , {field: 'high_count', title: '观众峰值', width: 100}
            , { field: 'ip_total', title: '累计IP', width: 120, sort: true, }
            , { field: 'new_fans_count', title: '新增粉丝数', width: 120, sort: true, }
            , { field: 'barrage_human_count', title: '累计发言人数', width: 120, sort: true, }
            // , {field: 'stream', title: '流名称', width: 230}
        ]]
        , page: true
        , limit: 20
        , height: 'full-140'
        , text: '对不起，加载出现异常！'
        , even: true
    });

    table.on("tool(LAY-livehistory-manage)", function (obj) {
        if (obj.event === "user_duration") {
            layer.open({
                type: 2,
                title: "用户在线时长",
                content: "/admin/live/user_duration?liveid=" + obj.data.liveid,
                maxmin: true,
                area: ["1200px", "600px"],
            });
        }
    });


    exports("livehistory", {});
});
